<template>
    <div class="song-list">
        <!-- 歌单详情 -->
        <van-nav-bar title="歌单详情" left-text="返回" left-arrow @click-left="onClickLeft" />
        <!-- 歌单的顶部 -->
        <div class="header">
            <img :src="song.logo" alt="">
            <h4>{{song.dissname}}</h4>
            <div class="nick">
                <img :src="song.headurl" alt="">
                <span>{{song.nickname}}</span>
            </div>
            <span>播放量:{{song.visitnum | numFilter(1)}}万</span>
        </div>
        <!-- 歌曲列表 -->
        <div class="list">
            <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
                <div v-for="(item,index) in songlist" :key="index">
                    <h3>{{item.songname}}</h3>
                    <div class="singer">
                        <span v-for="(singer,index) in item.singer" :key="index">
                            {{singer.name}}
                            <span v-show="index != item.singer.length -1">/</span>
                        </span>
                        <span v-show="item.albumname">
                            <span>.</span>
                            <span>{{item.albumname}}</span>
                        </span>
                    </div>
                </div>
            </van-list>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            song: {
                dissname: "", //标题
                logo: "", //歌单logo
                headurl: "",//歌单制作者头像
                nickname: "",//歌单制作者昵称
                visitnum: 0,//播放量
            },
            songlist: [],//歌曲列表
            songnum: 0,//歌曲列表数目
            list: [],//vant的list列表的数据
            loading: false,
            finished: false,
        };
    },
    created() {
        this.getListData();
    },
    methods: {
        getListData() {
            this.$request("get", "/songlist?id=" + this.$route.params.id)
                .then((res) => {
                    console.log(res);
                    this.song.dissname = res.data.dissname;
                    this.song.logo = res.data.logo;
                    this.song.headurl = res.data.headurl;
                    this.song.nickname = res.data.nickname;
                    this.song.visitnum = res.data.visitnum;
                    this.songlist = res.data.songlist; //获取歌曲列表信息
                    this.songnum = res.data.songnum; //获取歌曲数目
                }
                );
        },
        onClickLeft() {
            //如果历史记录大于1，那么返回上一层，如果历史积累小于等于1，返回到根路由
            window.history.length > 1 ? this.$router.go(-1) : this.$router.push('/')
            // this.$router.go(-1);
        },
        onLoad() {
            setTimeout(() => {
                //注意splice和slice方法的差异
                this.list = this.list.concat(this.songlist.splice(0, 10))
                //console.log(this.list);
                //加载状态结束
                this.loading = false;
                //数据全部加载完成
                if (this.list.length >= this.songnum) {
                    this.finished = true;
                }
            }, 1000);
        },
    

    },
};
</script>
<style scoped>
.header>img {
    border-radius: 1rem;
    width: 50%;
}

.nick {
    overflow: hidden;
    display: flex;
    /**弹性布局*/
    justify-content: center;
    /**弹性布局中的内容水平居中*/
    align-items: center;
    /**弹性布局中的内容垂直居中*/
    margin-bottom: 1rem;
}

.nick>img {
    height: 2rem;
    border-radius: 50%;
    margin: 0.5rem;
}

.nick>span {
    height: 2rem;
    font-size: 0.8rem;
    line-height: 2rem;
}

.singer {
    text-align: left;
}

.singers span {
    font-size: 0.8rem;
    color: rgb(160, 160, 190);
}

.singer>span:nth-last-child(1)>span:nth-child(1) {
    padding: 0 0.5rem;
    font-weight: 900;
    color: red;
}

.list {
    margin: 0 1rem;
}

.list h3 {
    text-align: left;
    font-size: 1rem;
}
</style>